﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using Assets.Scripts.Interface;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 随机死亡掉落物体
/// 死亡弹出物体
/// </summary>
public class RandomRelic : OnEntityDeath
{
    [Tooltip("道具落地点随机抖动大小")]
    public float shake = 1f;
    [Tooltip("随机生成道具的列表")]
    public RandomProp[] rdps;


    public override void OnDeath()
    {
        if (rdps.Length == 0) return;
        int index = UnityEngine.Random.Range(0, rdps.Length);
      //  print(index + "," + rdps.Length);
        BuidProp(rdps[index]);
    }

    /// <summary>
    /// 生成指定随机道具。
    /// </summary>
    /// <param name="rp"></param>
    void BuidProp(RandomProp rp)
    {
        Vector3 pos = transform.position;
        pos.z = 0;
        pos.x += UnityEngine.Random.Range(-shake, shake);
        pos.y += UnityEngine.Random.Range(-shake, shake);
        AProp ap=  GameObject.Instantiate(ResourceManager.Instance.propSources[(int)rp.propID],
            pos, Quaternion.identity).GetComponent<AProp>();
        ap.useCount = UnityEngine.Random.Range(rp.minCount, rp.maxCount + 1);
    }
    
}
/// <summary>
/// 一个随机道具的数据
/// 最小最大使用数量，道具id
/// </summary>
[System.Serializable]
public struct RandomProp
{

    public int minCount;
    public int maxCount;
    public PropId propID;

}
